#include <unistd.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>


int main(int argv, char** argc) {
	if (argv < 2) {
		printf("usage: client <serverip>");
	}
	int sock;
	struct sockaddr_in addr;
	if((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
	{
		perror("socket");
		exit(errno);
	}
	
	bzero(&addr, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_port = htons(3425);
	inet_aton(argc[1], &addr.sin_addr.s_addr);

	char message[256];
	sprintf(message, "client id: %d", getpid());
	char buf[sizeof(message)];

	sendto(sock, message, sizeof(message), 0, (struct sockaddr *) & addr, sizeof(addr));
	recvfrom(sock, buf, sizeof(message), 0, 0, 0);
	printf("answer: %s\n", buf);
	close(sock);

	return 0;
}

